<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
	 * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                imageInfo_1: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file:{maxSize: 1024*1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                categoryName: {
                    validators: {
                        notEmpty: {message: "分类名称不可为空"},
                        stringLength: {min: 2,max: 8,message: "分类名称长度为2至8"}
                    }
                },
				sortCode: {
					validators: {
						notEmpty: {message: "排序号不可为空"}
					},
                    numeric: {
                        message: '排序号只能输入数字'
                    }
				},
                moreUrl: {
                    validators: {
                        stringLength: {max: 150, message: "网址最大长度为150"},
						regexp: {
							regexp: validateUtil.webUrl,
							message: '请输入有效的网址'
						}
					}
                },
                moreAppUrl: {
                    validators: {
                        stringLength: {max: 150,message: "网址最大长度为150"},
						regexp: {
                            regexp: validateUtil.webUrl,
							 message: '请输入有效的网址'
						}
                    }
                },
                categoryDescription: {
                    validators: {
                        stringLength: {max: 150,message: "描述最大长度为150"}
                    }
                },
                keywords: {
                    validators: {
                        stringLength: {max: 150,message: "seo关键字最大长度为150"}
                    }
                }

            }
        });
    }

    /**
     * 添加分类
     */

	<shiro:hasPermission name="back_gotoPhoneHomeCategoryList_add">
		function addInfo(){
			$("#myModalLabel").empty().text("添加分类信息");
			/**清空隐藏域的值**/
			$("#categoryId").val("");
			$("#imageUrl_1").val("");
			$("#levelCode").val("");
			$("#isLeaf").val("");
			resetAddForm();
			/**如果有上传图片功能添加此代码，否则可以去掉**/
			/**
			 * 参数1 uploadIndex：页面文件的顺序位置  参数2 子系统目录  参数3 imageInfoPath：文件上传的存储目录
			 * 参数4 maxFileCount：最多上传文件数量 参数5 maxImageWidth：上传图片的最大宽度 参数6 maxImageHeight：上传图片的最大高度
			 */
			initImageForAdd(1,"sys_shop","image_phoneCategory",1,5000,5000);
		}
	</shiro:hasPermission>

    /**
     * 编辑分类
     */
	<shiro:hasPermission name="back_gotoPhoneHomeCategoryList_update">
		function editInfo(){
			$("#myModalLabel").empty().text("修改分类信息");
			/**获取选中行的id**/
			var selectedRow= $("#tt").bootstrapTable('getSelections');
			if(selectedRow.length==1){
				var id=selectedRow[0].categoryId;
				$("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
				$.ajax({
					type: "POST",
					dataType: "JSON",
					url: "${basePath}/back/phoneHomeCategory/getPhoneHomeCategoryObj.sjson",
					data: {id:id},
					success: function(result){
						var data = JSON.parse(result.data);
						$("#categoryId").val(data.categoryId);
						$("#parentId").val(data.parentId);
						$("#isLeaf").val(data.isLeaf);
						$("#levelCode").val(data.levelCode);
						$("#imageUrl_1").val(data.categoryImage);
						$("#categoryName").val(data.categoryName);
						$("#categoryDescription").val(data.categoryDescription);
						$("#sortCode").val(data.sortCode);
						$("#keywords").val(data.keywords);
						$("#isShow_"+data.isShow).attr("checked","checked");
						$("#moreUrl").val(data.moreUrl);
						$("#moreAppUrl").val(data.moreAppUrl);
						$("#categoryType").val(data.categoryType);

						/**
						 * 参数1 uploadIndex：页面文件的顺序位置 参数2 子系统目录  参数3 imageInfoPath：文件上传的存储目录
						 * 参数4 maxFileCount：最多上传文件数量  参数5 maxImageWidth：上传图片的最大宽度 参数6 maxImageHeight：上传图片的最大高度
						 * 参数7 visitFileRoot：图片预览的访问根路径 参数8 fileSaveUrl：图片预览的访问相对路径 参数9 fileName：文件原始的名称
						 */
						/**回写预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
						initImageForUpdate(1,"sys_shop","image_phoneCategory",1,5000,5000,"${uploadPath}",data.categoryImage);
						reValidateForm();
						removeValidateField('imageInfo_1');
					}
				});
			}else{
				showMsg("请选择一行记录！");
				$("#btn_edit").attr("data-target","");/**没有选中记录不可打开模态框**/
			}

		}
	</shiro:hasPermission>
</script>


<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">

				<form id="form1"  method="post" action="${basePath}/back/phoneHomeCategory/saveOrEditPhoneHomeCategory.sjson">
					<input id="categoryId" type="hidden" name="categoryId"/>
					<input id="parentId" type="hidden" name="parentId"/>
					<input id="isLeaf" type="hidden" name="isLeaf"/>
					<input id="levelCode" type="hidden" name="levelCode"/>

					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>分类图片:</td>
							<td class="toleft_td" colspan="3">
								<div class="container">
									<input id="imageUrl_1" type="hidden" name="categoryImage" value=""/>
									<div class="form-group" id="fileWrap1"></div>
								</div>
								<span style="color:red">提示：请上传规格宽100px，高100px的图片</span>
							</td>
						</tr>

						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>分类名称:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="categoryName" name="categoryName" placeholder="请输入名称"/>
								</div>
							</td>
							<td class="toright_td" width="150px"><span style="color:red">* </span>分类类型:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<select class="form-control input-sm" id="categoryType" name="categoryType">
									<c:forEach items="${redis:getPhoneKeyBook('phoneHomeCategory')}" var="pkb" >
										<option value="${pkb.value}">${pkb.name}</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>排序:&nbsp;&nbsp;</td>
							<td  class="toleft_td"  width="250px">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="sortCode" name="sortCode" placeholder="请输入排序号"/>
								</div>
							</td>
							<td class="toright_td" width="150px"><span style="color:red">* </span>是否显示:&nbsp;&nbsp;</td>
							<td  class="toleft_td"  width="250px">
								<label class="checkbox-inline">
									<input type="radio" name="isShow" id="isShow_1" class="radioInput" value="1" checked>&nbsp;是
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="isShow" id="isShow_0" class="radioInput" value="0">&nbsp;否
								</label>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">PC（更多）链接:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm " id="moreUrl" name="moreUrl" placeholder="请输入网址http://www.shopjsp.com"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">APP（更多）链接:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="moreAppUrl" name="moreAppUrl" placeholder="请输入网址http://www.shopjsp.com"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">分类描述:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="categoryDescription" name="categoryDescription" placeholder="请输入描述"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">SEO关键字:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="keywords" name="keywords" placeholder="请输入关键字"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>

		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
